# -*- coding: utf-8 -*-
import scrapy

from sina_stock.items import  SinaStockItem

class SinaSpider(scrapy.Spider):
    name = "sina"
    allowed_domains = ["vip.stock.finance.sina.com.cn"]
    start_urls = ['https://vip.stock.finance.sina.com.cn/q/view/hk_IPOList.php']

    def parse(self, response):
        item = SinaStockItem()
        subSelector=response.xpath('//div[@class="news"]')
        items=[]
        for sub in subSelector:
            item['stock'] = sub.xpath('.//table/tbody/tr/td[1]/a/text()').extract()
            item['stock_name'] = sub.xpath('.//table/tbody/tr/td[2]/a/text()').extract()
            item['ipo_price'] = sub.xpath('.//table/tbody/tr/td[3]/text()').extract()
            item['ipo_number'] = sub.xpath('.//table/tbody/tr/th[1]/text()').extract()
            item['money'] = sub.xpath('.//table/tbody/tr/th[2]/text()').extract()
            item['ipo_start'] = sub.xpath('.//table/tbody/tr/td[4]/text()').extract()
            item['ipo_end'] = sub.xpath('.//table/tbody/tr/td[5]/text()').extract()
            items.append(item)
            print(items)
        return  items
SinaSpider()

